package com.wz.wzliving.commodity.web;

import com.wz.wzliving.commodity.entity.CategoryEntity;
import com.wz.wzliving.commodity.service.CategoryService;
import com.wz.wzliving.commodity.vo.Catalog2Vo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {
    @Resource
    private CategoryService categoryService;
    @GetMapping(value = {"/", "index.html"})
    private String indexPage(Model model) {
//默认找的是 "classpath\templates\"+"index"+".html"
        List<CategoryEntity> level1Categorys = categoryService.getLevel1Categorys();
       model.addAttribute("categorys", level1Categorys);
        return "index";
    }
    @GetMapping(value = "/index/catalog.json")
    @ResponseBody
    public Map<String, List<Catalog2Vo>> getCatalogJson() {
        Map<String, List<Catalog2Vo>> catalogJson =
                categoryService.getCatalogJson();
        return catalogJson;

    }
}